//
//  ReadBookFirstAdvView.m
//  WNZSSQ
//
//  Created by JDKJ on 2018/12/8.
//  Copyright © 2018年 JDKJ. All rights reserved.
//

#import "ReadBookFirstAdvView.h"

@implementation ReadBookFirstAdvView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        /**
         上一章
         */
        UILabel *upNameLable = [[UILabel alloc]init];
        upNameLable.text = @"第一章 老杨出狱";
        upNameLable.textColor = TextColor1;
        upNameLable.font = [UIFont systemFontOfSize:10];
        self.upNameLable = upNameLable;
        [self addSubview:upNameLable];
        
        /**
         小说名
         */
        UILabel *bookNameLable = [[UILabel alloc]init];
        bookNameLable.text = @"盗墓笔记";
        bookNameLable.textColor = CSColorFromRGB(0x010100);
        bookNameLable.font = [UIFont systemFontOfSize:22];
        bookNameLable.textAlignment = NSTextAlignmentCenter;
        self.bookNameLable = bookNameLable;
        [self addSubview:bookNameLable];
        
        
        /**
         作者名
         */
        UILabel *nameLable = [[UILabel alloc]init];
        nameLable.text = @"作者：南派三叔";
        nameLable.textColor = TextColor1;
        nameLable.font = [UIFont systemFontOfSize:15];
        nameLable.textAlignment = NSTextAlignmentCenter;
        self.nameLable = nameLable;
        [self addSubview:nameLable];
        
        /**
         下一章
         */
        UILabel *downNameLable = [[UILabel alloc]init];
        downNameLable.text = @"下一章：盗墓笔记2";
        downNameLable.textColor = CSColorFromRGB(0x010100);
        downNameLable.font = [UIFont systemFontOfSize:16];
        downNameLable.textAlignment = NSTextAlignmentCenter;
        self.downNameLable = downNameLable;
        [self addSubview:downNameLable];
        
        /**
         广告图片
         */
        UIButton *advBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [advBtn setImage:[UIImage imageNamed:@"继续阅读广告图"] forState:UIControlStateNormal];
        advBtn.imageView.contentMode = UIViewContentModeScaleToFill;
        advBtn.imageView.layer.masksToBounds = YES;
        [self addSubview:advBtn];
        self.advBtn = advBtn;
        
        /**
         广告
         */
        UILabel *advLable = [[UILabel alloc]init];
        advLable.text = @"广告";
        advLable.textAlignment = NSTextAlignmentCenter;
        advLable.backgroundColor = CSColorFromRGBA(0x000000, 0.3);
        advLable.layer.cornerRadius = 2;
        advLable.clipsToBounds = YES;
        advLable.textColor = CSWhiteColor;
        advLable.font = [UIFont systemFontOfSize:12];
        self.advLable = advLable;
        [advBtn addSubview:advLable];
        
        /**
         去广告
         */
        UIButton *openVipBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [openVipBtn setTitle:@"去广告"];
        [openVipBtn setTitleColor:CSWhiteColor];
        [openVipBtn addTarget:self action:@selector(openVip)];
        openVipBtn.titleLabel.font = kFont16;
        openVipBtn.backgroundColor = CSColorFromRGB(0xCFCCCC);
        [self addSubview:openVipBtn];
        self.openVipBtn = openVipBtn;
        
        /**
         继续阅读
         */
        UIButton *goReadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [goReadBtn setTitle:@"继续阅读"];
        [goReadBtn setTitleColor:CSWhiteColor];
        goReadBtn.backgroundColor = CSColorFromRGB(0xE7494C);
        [goReadBtn addTarget:self action:@selector(goRead)];
        goReadBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 0,TabBarHeightIphonexSafe , 0);
        goReadBtn.titleLabel.font = kFont16;
        [self addSubview:goReadBtn];
        self.goReadBtn = goReadBtn;
        
        
        [self setConstraints];
        
    }
    return self;
    
}

-(void)setConstraints
{
    //设置约束条件
    
    /**
     上一章
     */
    [self.upNameLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self).offset(AdaptStatusBar);
        make.left.mas_equalTo(self).offset(12);
        
    }];
    
    /**
     小说名
     */
    [self.bookNameLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self).offset(adaptNavagationBar);
        make.left.mas_equalTo(self).offset(12);
        make.right.mas_equalTo(self).offset(-12);
        make.height.mas_equalTo(21);
        
    }];
    
    /**
     作者名
     */
    [self.nameLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.bookNameLable.mas_bottom).offset(15);
        make.left.mas_equalTo(self).offset(12);
        make.right.mas_equalTo(self).offset(-12);
        make.height.mas_equalTo(14);
        
    }];
    
    
    /**
     下一章
     */
    [self.downNameLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.nameLable.mas_bottom).offset(Iphone5?25:36);
        make.left.mas_equalTo(self).offset(12);
        make.right.mas_equalTo(self).offset(-12);
        make.height.mas_equalTo(14);
        
    }];
    
    
    /**
     广告图片
     */
    [self.advBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.downNameLable.mas_bottom).offset(Iphone5?30:48);
        make.left.mas_equalTo(self).offset(12);
        make.right.mas_equalTo(self).offset(-12);
        make.center.mas_equalTo(self);
        make.height.mas_equalTo((SCREENHEIGHT - adaptNavagationBar - adaptTabBar)/2);
        
    }];
    
    /**
     广告
     */
    [self.advLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(35);
        make.height.mas_equalTo(16);
        make.top.mas_equalTo(self.advBtn).offset(0);
        make.right.mas_equalTo(self.advBtn).offset(-0);
        
    }];
    
    /**
     去广告
     */
    [self.openVipBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(72);
        make.height.mas_equalTo(35);
        make.top.mas_equalTo(self.advBtn.mas_bottom);
        make.right.mas_equalTo(self.advBtn);
        
    }];
    
    /**
     继续阅读
     */
    [self.goReadBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.bottom.right.mas_equalTo(self);
        make.height.mas_equalTo(adaptTabBar);
        
    }];
    
}


-(void)openVip
{
    OpenVipView *openView = [[OpenVipView alloc]init];
    [openView showWithAnimation];
}

-(void)goRead
{
    [self.viewController.navigationController popViewControllerAnimated:NO];
}

@end
